unit WinForm;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel, StrUtils, SysUtils,
  System.Windows.Forms, System.Data, SoundManager, System.Resources;

type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    Ajouter: System.Windows.Forms.Button;
    Jouer: System.Windows.Forms.Button;
    ListBox1: System.Windows.Forms.ListBox;
    ListBox2: System.Windows.Forms.ListBox;
    ListBox3: System.Windows.Forms.ListBox;
    Stop: System.Windows.Forms.Button;
    TrackBar1: System.Windows.Forms.TrackBar;
    BVolume: System.Windows.Forms.Button;
    Label1: System.Windows.Forms.Label;
    Label2: System.Windows.Forms.Label;
    Label3: System.Windows.Forms.Label;
    Button1: System.Windows.Forms.Button;
    OpenFileDialog1: System.Windows.Forms.OpenFileDialog;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
    procedure Button2_Click(sender: System.Object; e: System.EventArgs);

    procedure Button3_Click(sender: System.Object; e: System.EventArgs);

    procedure Button1_Click1(sender: System.Object; e: System.EventArgs);

    procedure Button1_Click2(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
    function getID(name : String) : Integer;
  public
    Music : SoundM;
    constructor Create;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]

implementation

{$AUTOBOX ON}

{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm.InitializeComponent;
var
  resources: System.Resources.ResourceManager;
begin
  resources := System.Resources.ResourceManager.Create(TypeOf(TWinForm));
  Self.Ajouter := System.Windows.Forms.Button.Create;
  Self.Jouer := System.Windows.Forms.Button.Create;
  Self.ListBox1 := System.Windows.Forms.ListBox.Create;
  Self.ListBox2 := System.Windows.Forms.ListBox.Create;
  Self.ListBox3 := System.Windows.Forms.ListBox.Create;
  Self.Stop := System.Windows.Forms.Button.Create;
  Self.TrackBar1 := System.Windows.Forms.TrackBar.Create;
  Self.BVolume := System.Windows.Forms.Button.Create;
  Self.Label1 := System.Windows.Forms.Label.Create;
  Self.Label2 := System.Windows.Forms.Label.Create;
  Self.Label3 := System.Windows.Forms.Label.Create;
  Self.Button1 := System.Windows.Forms.Button.Create;
  Self.OpenFileDialog1 := System.Windows.Forms.OpenFileDialog.Create;
  (System.ComponentModel.ISupportInitialize(Self.TrackBar1)).BeginInit;
  Self.SuspendLayout;
  // 
  // Ajouter
  // 
  Self.Ajouter.Location := System.Drawing.Point.Create(264, 72);
  Self.Ajouter.Name := 'Ajouter';
  Self.Ajouter.Size := System.Drawing.Size.Create(72, 24);
  Self.Ajouter.TabIndex := 0;
  Self.Ajouter.Text := 'Ajouter';
  Include(Self.Ajouter.Click, Self.Button1_Click);
  // 
  // Jouer
  // 
  Self.Jouer.Location := System.Drawing.Point.Create(264, 160);
  Self.Jouer.Name := 'Jouer';
  Self.Jouer.Size := System.Drawing.Size.Create(72, 23);
  Self.Jouer.TabIndex := 2;
  Self.Jouer.Text := 'Jouer';
  Include(Self.Jouer.Click, Self.Button2_Click);
  // 
  // ListBox1
  // 
  Self.ListBox1.Location := System.Drawing.Point.Create(8, 32);
  Self.ListBox1.Name := 'ListBox1';
  Self.ListBox1.Size := System.Drawing.Size.Create(248, 69);
  Self.ListBox1.TabIndex := 3;
  // 
  // ListBox2
  // 
  Self.ListBox2.Location := System.Drawing.Point.Create(8, 136);
  Self.ListBox2.Name := 'ListBox2';
  Self.ListBox2.Size := System.Drawing.Size.Create(248, 69);
  Self.ListBox2.TabIndex := 4;
  // 
  // ListBox3
  // 
  Self.ListBox3.Location := System.Drawing.Point.Create(8, 240);
  Self.ListBox3.Name := 'ListBox3';
  Self.ListBox3.Size := System.Drawing.Size.Create(248, 69);
  Self.ListBox3.TabIndex := 5;
  // 
  // Stop
  // 
  Self.Stop.Location := System.Drawing.Point.Create(264, 256);
  Self.Stop.Name := 'Stop';
  Self.Stop.Size := System.Drawing.Size.Create(72, 23);
  Self.Stop.TabIndex := 6;
  Self.Stop.Text := 'Stop';
  Include(Self.Stop.Click, Self.Button3_Click);
  // 
  // TrackBar1
  // 
  Self.TrackBar1.LargeChange := 3;
  Self.TrackBar1.Location := System.Drawing.Point.Create(8, 328);
  Self.TrackBar1.Maximum := 20;
  Self.TrackBar1.Name := 'TrackBar1';
  Self.TrackBar1.Size := System.Drawing.Size.Create(248, 42);
  Self.TrackBar1.TabIndex := 3;
  // 
  // BVolume
  // 
  Self.BVolume.Location := System.Drawing.Point.Create(264, 336);
  Self.BVolume.Name := 'BVolume';
  Self.BVolume.Size := System.Drawing.Size.Create(72, 23);
  Self.BVolume.TabIndex := 7;
  Self.BVolume.Text := 'Modifier';
  Include(Self.BVolume.Click, Self.Button1_Click1);
  // 
  // Label1
  // 
  Self.Label1.Location := System.Drawing.Point.Create(0, 8);
  Self.Label1.Name := 'Label1';
  Self.Label1.TabIndex := 8;
  Self.Label1.Text := 'Bibliotheque :';
  // 
  // Label2
  // 
  Self.Label2.Location := System.Drawing.Point.Create(0, 112);
  Self.Label2.Name := 'Label2';
  Self.Label2.TabIndex := 9;
  Self.Label2.Text := 'Liste de lecture :';
  // 
  // Label3
  // 
  Self.Label3.Location := System.Drawing.Point.Create(0, 216);
  Self.Label3.Name := 'Label3';
  Self.Label3.TabIndex := 10;
  Self.Label3.Text := 'En lecture :';
  // 
  // Button1
  // 
  Self.Button1.Location := System.Drawing.Point.Create(264, 40);
  Self.Button1.Name := 'Button1';
  Self.Button1.Size := System.Drawing.Size.Create(72, 23);
  Self.Button1.TabIndex := 11;
  Self.Button1.Text := 'Importer';
  Include(Self.Button1.Click, Self.Button1_Click2);
  // 
  // TWinForm
  // 
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
  Self.ClientSize := System.Drawing.Size.Create(344, 365);
  Self.Controls.Add(Self.Button1);
  Self.Controls.Add(Self.Label3);
  Self.Controls.Add(Self.Label2);
  Self.Controls.Add(Self.Label1);
  Self.Controls.Add(Self.BVolume);
  Self.Controls.Add(Self.TrackBar1);
  Self.Controls.Add(Self.Ajouter);
  Self.Controls.Add(Self.Stop);
  Self.Controls.Add(Self.ListBox3);
  Self.Controls.Add(Self.ListBox2);
  Self.Controls.Add(Self.ListBox1);
  Self.Controls.Add(Self.Jouer);
  Self.Icon := (System.Drawing.Icon(resources.GetObject('$this.Icon')));
  Self.Name := 'TWinForm';
  Self.Text := 'Life is music';
  (System.ComponentModel.ISupportInitialize(Self.TrackBar1)).EndInit;
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
   Music := SoundM.Create;
end;

procedure TWinForm.Button1_Click2(sender: System.Object; e: System.EventArgs);
var
  F : OpenFileDialog;
  pos : Integer;
begin
 F := OpenFileDialog.Create;
 F.Filter := 'Wav|*.wav';
 F.Title := 'Importer';
 F.ShowDialog;
 pos := LastDelimiter('\', F.FileName);
 ListBox1.Items.Add(AnsiRightStr(F.FileName, Length(F.Filename) - pos));

end;


procedure TWinForm.Button1_Click1(sender: System.Object; e: System.EventArgs);
var
  NewVolume : Integer;
begin
  NewVolume := ((-4000) + (TrackBar1.Value * (200)));
  Music.Volume(NewVolume, getID(ListBox3.SelectedItem.ToString));
end;


procedure TWinForm.Button3_Click(sender: System.Object; e: System.EventArgs);
begin
  Music.Stop(getID(ListBox3.SelectedItem.ToString));
  ListBox2.Items.Add(ListBox3.SelectedItem);
  ListBox3.Items.RemoveAt(ListBox3.SelectedIndex);
end;


procedure TWinForm.Button2_Click(sender: System.Object; e: System.EventArgs);
begin

  Music.Play(getID(ListBox2.SelectedItem.ToString));
  ListBox3.Items.Add(ListBox2.SelectedItem);
  ListBox2.Items.RemoveAt(ListBox2.SelectedIndex);


end;

function TWinForm.getID(name : String) : Integer;
var
  i : Integer;
begin
  i := 0;
  result := 0;
  while(i < Music.Collection.Counter) do
    begin
      if (Music.Collection.Items[i].Title = name) then
        begin
          result := i;
          i := i + 1;
        end
      else
        begin
          i := i + 1;
        end;
    end;

end;

procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
begin

      Music.AddSound(ListBox1.SelectedItem.ToString);
      ListBox2.Items.Add(ListBox1.SelectedItem);
      ListBox1.Items.RemoveAt(ListBox1.SelectedIndex);
      //Writeln ('Votre son a l''ID: ', Music.Collection.Counter-1);
end;

end.

